$(function () {
    $("#jqGrid").jqGrid({
        url: '/platform/oem/bankList',
        datatype: "json",
        colModel: [
			{ label: '编号', name: 'bankId', index: 'bankId', width: 50 ,key:true,hidden:true},
            { label: '银行名称', name: 'bankName', index: 'cardName'},
            { label: '银行链接', name: 'bankLink', index: 'bankLink' },
			{ label: '查询链接', name: 'bankQueryUrl', index: 'bankQueryUrl'},
            { label: '图标' ,name:'bankIcon',index:'bankIcon',formatter:function (value) {
                return '<img src="'+value+'" width="35" height="35" />';
            }}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "result.list",
            page: "result.currPage",
            total: "result.totalPage",
            records: "result.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条\
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
    $("#cardImage").click(function () {
        $("#cardInput").click();
    });
    $("#cardInput").change(function () {
        var objUrl = getObjectURL(this.files[0]); //获取图片的路径，该路径不是图片在本地的路径
        if (objUrl != null) {
            $("#cardImage").attr("src", objUrl);
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		showInfo:false,
		title: null,
		isUpdate:false,
        bank: {},
        tags:[],
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.showInfo = true;
			vm.title = "新增";
			vm.bank = {};
		},

        saveOrUpdate: function (event) {
			var urlStr = "/platform/oem/bankAdd";
			// return;
            $.ajaxFileUpload({
                url: urlStr,
                data: JSON.parse(JSON.stringify(vm.bank)),
                type: "POST",
                contentType: "multipart/form-data",
                secureuri: false,
                fileElementId: 'cardInput',
                dataType: 'json',
                success: function (result) {
                    if (result.code == 200) {
                        vm.reload();
                        alert("操作成功");
                    } else {
                        alert(result.message);
                        if (this.lecture.id == null) {
                            $("#cardImage").attr("src", "");
                        }
                    }
                },
                complete: function () {
                    $("#cardInput").replaceWith('<input type="file" id="cardInput" accept="image/*" name="icon" style="display: none;" class="form-control"/>');
                    $("#cardInput").change(function () {
                        var objUrl = getObjectURL(this.files[0]); //获取图片的路径，该路径不是图片在本地的路径
                        if (objUrl != null) {
                            $("#cardImage").attr("src", objUrl);
                        }
                    });
                },
                error: function (e) {
                    console.log("error", e);
                    $("#cardImage").attr("src", "");
                    alert("请求失败，请重试");
                }
            });
		},
		del: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
				    url: "/platform/oem/bankDel/"+id,
				    success: function(r){
						if(r.code == 200){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.message);
						}
					}
				});
			});
		},
        reload: function (event) {
            vm.showList = true;
            vm.showInfo = false;
			$("#jqGrid").jqGrid('setGridParam',{
                page:1
            }).trigger("reloadGrid");
            vm.isUpdate = false;
		}
	}
});